<?php
class Banner_model extends CI_Model{
	private $db;
	private $table_name = 'banner';
	function __construct(){
		parent::__construct();
		$this->db=$this->load->database('master',true);
	}

	public function writeLog($data)
	{
		return $this->db->insert($this->table_name, $data);
	}

	//获取banner
	public function getBanner($where){
		$result = $this->db->where($where)->order_by('id','DESC')->get($this->table_name)->result_array();

		$res = $this->db->select('id')->where($where)->get($this->table_name)->result_array();
		$count = count($res);

		return array('list' => $result,'total' => $count);
	}
	
	//获取单个banner
	public function getOne($banner_id){
		return $this->db->get_where($this->table_name, array('id' => $banner_id))->row_array();
	}
	
	//添加banner
	public function insertBanner($data){
	
		$result = $this->db->insert($this->table_name, $data);
	
		if($result){
			return array('ack' => true,'msg' => '添加banner成功');
		}else{
			return array('ack' => false, 'msg' => '添加banner失败');
		}
	}
	
	//更新banner信息
	public function updateBanner($data,$where){
		$result = $this->db->where($where)->update($this->table_name,$data);
		if($result){
			return array('ack' => true,'msg' => '修改成功');
		}else{
			return array('ack' => false, 'msg' => '修改失败');
		}
	}
}